<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>Xiuxiu Open PlatForm</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script src="http://open.web.meitu.com/sources/xiuxiu.js" type="text/javascript"></script>
    <script src="../../../common/ueditor-common.js" type="text/javascript"></script>
    <script type="text/javascript" src="../internal.js?t=1458602018"></script>
    <script type="text/javascript">
        //用于嵌入美图秀秀的编辑器功能
        window.onload = function () {
        	var topUtil = window.top.cmedit.global;
            var manuscriptid = getArgsFromHref("manuscriptid");
            var loadImagePath = getArgsFromHref("imagepath");
            var contextpath = window.sessionStorage.getItem("cms_serverPath");
            /*第1个参数是加载编辑器div容器，第2个参数是编辑器类型，第3个参数是div容器宽，第4个参数是div容器高*/
            xiuxiu.embedSWF("altContent", 3, "100%", "80.8%");
            //修改为您自己的图片上传接口
            xiuxiu.setUploadURL(contextpath  + "/UploadController/uploadImage");
            //设置上传类型为表单上传
            xiuxiu.setUploadType (3);
            //上传前的参数设置
            xiuxiu.onBeforeUpload = function (data, id) {
                xiuxiu.setUploadArgs({filetype: data.type, type: "image", filename: data.name});
            }
            xiuxiu.onInit = function () {
                if (loadImagePath != null && loadImagePath != undefined && loadImagePath != "") {
                    xiuxiu.loadPhoto(loadImagePath);//修改为要处理的图片url，
                }
            };
            
            xiuxiu.onSaveBase64Image = function (data, fileName, fileType, id)
        	{
            	var imgArray = new Array();
            	var imgObj = {
          				imgBase64:data,
          				imgSuffix:"png",
          				fileName:fileName
          		};
            	imgArray.push(imgObj);
            	 var postData = {
                 		 mainGuid : manuscriptid,
                 		 images : JSON.stringify(imgArray)
                 	  };
            	 
            	 /**
            	  *上传美图秀秀的图片
            	  */
            	 topUtil.ajaxRequest({
           			async: false,
           			url: contextpath + "UploadController/uploadImageForMeitu",
           			type: 'POST',
           			data : postData,
           			dataType : 'json',
           			success: function (data) {
           				if(data.status==true||data.status=="true"){
           					//插入操作
           					var appendHtml = '';
           					var imgList = data.data;
           					var dataUrl = '';
           					var ue = UE.getEditor("editer_");
           					for(var i = 0;i < imgList.length;i++){
           						dataUrl = imgList[i].streamPath;
           					}
           					
           					//编辑图片
           					if (loadImagePath != null && loadImagePath != undefined && loadImagePath != "") {
           						var htmlcontent = ue.getContent();
           						var newhtml = htmlcontent.replace(loadImagePath, dataUrl);
                                ue.setContent(newhtml);	
           					}else{
           					//插入图片
           						editor.focus();
                                var imghtml = '<img src="' + dataUrl + '"></img>';
                                ue.execCommand('inserthtml', imghtml);
           					}
                            
           					//设置为缩略图操作
                            dialog.close();
           				}else{
           					alert(data.msg);
           				}
           			}
           		});
        	}
            
            /*  xiuxiu.onUploadResponse = function (data) {
                //返回的data为上传后台返回的流媒体地址
                if(data != null && data != "") {
                    var dataUrl = data.replace(/(^\s+)|(\s+$)/g, "");//去掉回车换行
                    if (loadImagePath != null && loadImagePath != undefined && loadImagePath != "") {
                        //编辑图片加水印,图片地址为loadImagePath的地址
                        var htmlcontent = editor.getContent();
                        var newhtml = htmlcontent.replace(loadImagePath, dataUrl);
                        editor.setContent(newhtml);
                    } else {
                        //没有图片的加载路径，因此为添加水印图片
                        editor.focus();
                        var imghtml = '<img width="326" height="326" src="' + dataUrl + '"></img>';
                        editor.execCommand('inserthtml', imghtml);
                    }
                    dialog.close();
                } else {
                    window.top.alertMsgNoCancel("上传发生错误，请检查服务器是否授予美图秀秀访问权限!");
                }
            };  */
        };
    </script>
    <style type="text/css">
        html, body {
            height: 100%;
            overflow: hidden;
        }

        body {
            margin: 0;
        }
    </style>
</head>
<body>
<div id="altContent">
</div>
</body>
</html>